package com.youmu.sichuansfc.dao.impl;

import com.youmu.sichuansfc.dao.UserDao;
import com.youmu.sichuansfc.domain.YoumuUser;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

@Repository
public class UserDaoImpl implements UserDao{

    private EntityManager em;
    @PersistenceContext
    public void setEm(EntityManager em) {
        this.em = em;
    }

    @Override
	public YoumuUser findbyLoging(String name, String password) {
        String hql = "from YoumuUser where name=:name and password=:password ";
        List<YoumuUser> youmuUsers = em.createQuery(hql, YoumuUser.class)
                .setParameter("name", name)
                .setParameter("password", password)
                .getResultList();
        if (youmuUsers != null && youmuUsers.size() > 0){
            return  youmuUsers.get(0);
        }
        return null;
	}
}
